Algunos problemas de DP. Uno de ellos utiliza BigInteger e I/O de Java.
[and.git] / 10261 - Ferry loading / 10261.cpp
blob715ea10c4d99cd03090263005f68a3920659c035
1 #include <iostream>
2 #include <algorithm>
3 #include <climits>
4 #include <vector>
6 using namespace std;
8 int capacity, n;
9 vector<int> w;
11 int dp(int p, int s, int i){
12 if (p > capacity || s > capacity)
13 return INT_MIN;
14 if (i >= n)
15 return 0;
17 return max(dp(p + w[i], s, i+1) + 1, dp(p, s + w[i], i+1) + 1);
21 int main(){
22 int C;
23 cin >> C;
24 while (C--){
25 cin >> capacity;
26 capacity *= 100;
28 w.clear();
29 int x;
30 while(cin >> x && x){
31 w.push_back(x);
34 n = w.size();
36 cout << dp(0,0,0) << endl;
38 return 0;